<?php
namespace App\Traits\Templates;

// 水吧打印模板 对应型号 w1
trait WaterTemplate
{
	protected $waterOrderData = [
        'room_name' => '桌台20号',
        'order_number' => 'NO:2020111009',
        'cashier' => '阿伟',
        'created_at' => '2020/11/10 12:00',
        'printed_at' => '2020/11/10 12:00',//出单时间
        'goods' => [
            [
                'name' => '格瓦斯',
                'number' => 2
            ],
            [
                'name' => '珠江啤酒',
                'number' => 2
            ]
        ]
    ];

    protected $waterSingleData = [
    	'order_no' => '20201110',
    	'cashier' => '阿伟',
    	'name' => '矿泉水',
    	'price' => '29',
    	'number' => 2,
    	'created_at' => '10/11 12:00'
    ];
	// 商品分单
	public function WaterSingleTemplate($data = [])
	{
		$heads  = '<FS2><LR>,NO:'.$data['order_no'].'</LR></FS2>';
		$heads .= '<LR>收银员：'.$data['cashier'].'</LR>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<FS><LR>'.$data['name'].',</LR></FS>';
		$heads .= '<table><tr><td> </td><td>'.$data['number'].' 份</td><td>'.$data['price'].'元</td></tr></table>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<table><tr><td>小计：</td><td><FS>'.$data['number'] * $data['price'].'元</FS></td><td>'.$data['created_at'].'</td></tr></table>';
		$heads .= '<LR>出品点：水吧,</LR>';

		return $heads;
	}

	// 商品总单
	public function WaterOrderTemplate($data = [])
	{
		$count = 0;// 合计
		// 页首
		$heads  = '<center>@@2点单[水吧-水吧总单]</center>';
		$heads .= '<LR>桌台号：,'.$data['room_name'].'</LR>';
		$heads .= '<LR>订单号:'.$data['order_number'].'</LR>';
		// $heads .= '<LR>订单号:6,人数:5</LR>';
		// $heads .= '<LR>出单序号:,7</LR>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<LR>商品,数量</LR>';

		// 商品主体
		$order  = '<table>';
		if(isset($data['goods']) && !empty($data['goods'])){
			foreach ($data['goods'] as $k => $v) {
				$index = $k + 1;
				$order .= '<tr><td>'.$index.'</td><td>'.$v['name'].'</td><td>'.$v['number'].'/份</td></tr>';
				$count += $v['number'];
			}
		}
		$order .= '</table>';

		// footer 
		$footer  = '<center>----------------------------------------</center>';
		$footer .= '<LR>合计, '.$count.'</LR>';
		$footer .= '<center>----------------------------------------</center>';
		$footer .= '<LR>收银员:'.$data['cashier'].',</LR>';
		$footer .= '<LR>开单:'.$data['created_at'].', 出单:'.$data['printed_at'].'</LR>';

		return  $heads . $order . $footer;
	}
}